package com.gxz.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;

public class JdbcConfig {
    @Value("${jdbc.driverClass}")
    String driver;
    @Value("${jdbc.url}")
    String url;
    @Value("${jdbc.username}")
    String user;
    @Value("${jdbc.password}")
    String password;
  @Bean
  DataSource dataSource() {
      DruidDataSource dataSource = new DruidDataSource();
      dataSource.setDriverClassName(driver);
      dataSource.setUrl(url);
      dataSource.setUsername(user);
      dataSource.setPassword(password);
      return dataSource;
  }

  @Bean
  PlatformTransactionManager transactionManager(DataSource dataSource) {
      DataSourceTransactionManager ptm = new DataSourceTransactionManager();
      ptm.setDataSource(dataSource);
      return ptm;
  }

}
